package com.yunji.aggregate.convert;

import com.yunji.aggregate.model.dto.analysis.LinkageQueryParam;
import com.yunji.aggregate.model.dto.analysis.WalletTurnoverParam;
import com.yunji.aggregate.model.dto.order.StatsOrdersParams;
import com.yunji.common.enums.business.TradeMode;
import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.context.SystemContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/16 16:08
 * @description : TODO
 **/
public class AggregateParamConvert {

    /**
     * @Title currentUser
     * @Desc 根据当前用户设置参数
     * @Date 2024-09-06 09:25:09.200
     * @Return StatsOrdersParams
     */
    public static StatsOrdersParams currentUser() {
        LoginInfo user = SystemContext.getUser();
        StatsOrdersParams statsParams = new StatsOrdersParams();
        Long belongId = user.getBelongId();
        String userType = user.getUserType();
        if (UserType.AGENT.getCode().equals(userType)) {
            statsParams.setParentId(belongId);
        }

        if (UserType.SITE.getCode().equals(userType)) {
            statsParams.setBelongId(belongId);
        }
        return statsParams;
    }

    public static void handleLinkageQuery(LinkageQueryParam param) {
        LoginInfo user = SystemContext.getUser();
        Long belongId = user.getBelongId();
        String userType = user.getUserType();
        if (BeanUtils.equals(userType, UserType.AGENT.getCode())) {
            param.setParentId(belongId);
        } else if (BeanUtils.equals(userType, UserType.SITE.getCode())) {
            param.setBelongId(belongId);
        }
    }

    /**
     * @param param
     * @Title turnoverParam
     * @Desc 转换参数
     * @Date 2024-10-28 14:43:54.449
     */
    public static void turnoverParam(WalletTurnoverParam param) {
        List<Integer> statusList = param.getTurnoverStatus();

        if (BeanUtils.isNotNull(statusList)) {
            List<Integer> tradeStatusList = new ArrayList<>();
            List<Integer> tradeModeList = new ArrayList<>();

            for (Integer status : statusList) {

                Integer tradeStatus = null;
                Integer tradeMode = null;

                switch (status) {
                    case 0:
                        tradeMode = TradeMode.ORDER.getCode();
                        tradeStatus = 4;
                        break;
                    case 1:
                        tradeMode = TradeMode.REFUND.getCode();
                        tradeStatus = 4;
                        break;
                    case 2:
                        tradeMode = TradeMode.REFUND.getCode();
                        tradeStatus = 5;
                        break;
                    case 3:
                        tradeMode = TradeMode.PAYOUT.getCode();
                        tradeStatus = 4;
                        break;
                    case 4:
                        tradeMode = TradeMode.PAYOUT.getCode();
                        tradeStatus = 5;
                        break;
                    default:
                }

                tradeModeList.add(tradeMode);
                tradeStatusList.add(tradeStatus);
            }

            param.setTradeMode(tradeModeList);
            param.setTradeStatus(tradeStatusList);
        }
    }

//    /**
//     * @param params 过滤条件
//     * @Title handleParam
//     * @Desc 处理用户查询参数
//     * @Date 2024-09-10 14:26:32.026
//     */
//    public static void tradeParam(TradeCountParam params) {
//        // 如果是代理商就传agentId 查看所有人信息
//        LoginInfo user = SystemContext.getUser();
//        Long belongId = user.getBelongId();
//        String userType = user.getUserType();
//        if (UserType.AGENT.getCode().equals(userType)) {
//            params.setParentId(belongId);
//        }
//        if (UserType.SITE.getCode().equals(userType)) {
//            params.setBelongId(belongId);
//        }
//    }
}
